import gtk.gdk
from gtk import *
from utils import *
from os.path import basename
from urllib2 import url2pathname
from xml.sax.saxutils import escape

class PlaylistAdmin:
    def __init__(self, model):
        self.model = model

    def insert_entry(res):
        if res.iserror():
            "Could not insert entry"
            return
        info = res.value()
        values = []
        for k in "url", "title", "artist", "album", "picture_front", "id":
            try:
                v = info[k]
            except KeyError:
                v = ""
            values.append(v)
        url, title, artist, album, picture_front, _id = values
        id = int(_id)
        markup = make_markup(url, title, artist, album)
        picture_path = os.path.join(CACHE, picture_front)
        if os.path.exists(picture_path):
            pb = gtk.gdk.pixbuf_new_from_file_at_size(picture_path, 32, 32)
        else:
            image = gtk.Image()
            pb = image.get_pixmap()
        self.model.append([pb, markup, id, True])
